/**
  * Created by wyc on 6/8/2017.
  *
  *Find the Kth element of a list.
  *By convention, the first element in the list is element 0.
  *Example:
  *scala> nth(2, List(1, 1, 2, 3, 5, 8))
  *res0: Int = 2
  */

package test

import ninenineqs._

class test_p03 extends UnitSpec{
  feature(this.getClass.toString) {
    val L1 = List(9, 1, 2, 3, 5, 8)
    val L2 = List[Int]()
    val L3 = List(4)

    val Ts:List[(Int, List[Int]) => Int]=List(
      p03.nth_v1,
      p03.nth_v2,
      p03.nth_v3
    )

    var v = 1
    for ( func <- Ts ) {
      scenario("nth_v" + v) {
        assert(func(0, L1) == 9)
        assert(func(2, L1) == 2)
        try {
          func(100, L1)
        }
        catch {
          case _ : NoSuchElementException => //Expected
        }
        try {
          func(2, L2)
        }
        catch {
          case _ : NoSuchElementException => //Expected
        }
        assert(func(0, L3) == 4)
      }
      v += 1
    }
  }
}
